#SingleInstance, Force
;~ #Include C:\Dropbox\AHK\AHK Examples & Refs\Functions.ahk
SendMode Input 
SetWorkingDir, %A_ScriptDir%  
DetectHiddenText, on
DetectHiddenWindows, on
SetTitleMatchMode, 2
Functions()
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-







;~ !f9::
	;~ objtype=
	;~ sbTxt=
	
	;~ MouseGetPos,,,id
	;~ WinActivate, ahk_id %id%
	;~ WinWaitActive, ahk_id %id%
	;~ win := WinExist("A")
	
	;~ StatusBarGetText,sbtxt,, ahk_id %win%
	;~ if !sbTxt
		;~ return
	
	
	
	Clipboard := sbTxt
	MsgBox done
	ExitApp
	;~ IfInString, sbTxt, http://cwiprod.corp.halliburton.com/cwi
	;~ {	
		;~ url:=sbTxt
		
					
		;~ ;________________
		;~ ;	Get Part ID
		;~ StringReplace, partid, url, jsp?id=, $
		;~ StringSplit,partID, partid, $
		;~ partID := partID2
		
		;~ Gui, 47:Add, Text, x22 y5 w160 h20 +Center, Enter a label for the object
		
		;~ Gui, 47:Add, Radio, xm+5 y25 w60 h30 +Left vRta, RTA
		;~ Gui, 47:Add, Radio, x+0 yp w60 h30 +Left vTask, Task
		;~ Gui, 47:Add, Radio, x+0 yp w60 h30 +Left +Checked, Other
		
		
		;~ Gui, 47:Add, Edit, x22 y60 w160 h25 vlabel,
		;~ Gui, 47:Add, Button, x52 y85 w90 h30 gsubmit, Submit
		;~ Gui, 47:Show, w190 h125, Create CWI Label
		;~ return	
	;~ } 
;~ return
	
	
;~ Submit:
	;~ gui, Submit
	;~ gui, 47:Destroy
	
	;~ objType := RTA ? "Rta" : Task ? "Task" : ""
	

	;~ cwi := new cwi()
	
	;~ ;==========================
	;~ ; WRITE INFO TO INI FILES
	;~ ;===========================
		
		;~ ;________________________________________________________
		;~ ; 	RTA >> Write ID to rtaid.ini [rtaids] section
		;~ ;
		;~ if (objType = "Rta")		
			;~ cwi.Add_rtaID(Label, trim(partID))

		;~ ;_________________________________________________________
		;~ ; 	TASK >> Write ID to rtaid.ini [taskids] section
		;~ ;
		;~ else if (objType = "Task")
			;~ IniWrite, % trim(partID), %links%\rtaID.ini, taskids, %label%
		
		;~ ;_________________________________________________________
		;~ ; 	ALL (EXCEPT task/RTA) >> Write ID to objectids.ini
		;~ ;
		;~ else
			;~ cwi.Add_id(Label, trim(partID))

		;~ ;________________________________________
		;~ ; 	PART >> Also write SAP num info
		;~ ;
		;~ if ((objType = "Part") && (sapNum != label))  ;Don't write if SAP num used as label
			;~ cwi.Add_sapNum(Label, Trim(sapNum))
		
;~ return



		;~ 47GuiClose:
		;~ 47Guiescape:
		;~ gui, 47:Destroy
		;~ return



	CWI := new cwi()
	If (ErrorLevel){
		MsgBox error creating class
		ExitApp
	}
	
	
	RegRead, installDir, HKCu, Software\PM App Launcher, InstallDir
	
	
	;__________________________________
	; 		GET THE MANDREL ASSY NUMBER
	;
	mandAssyNum := InputBox("Quick SC Get","Enter top level number of assy:")

	if (strlen(mandAssyNum)<>9 || StrLeft(mandAssyNum,6)<>"9290-6"){
		msgbox  Wrong format. This is designed for 9290-6XXX numbers only. (For now)
		ExitApp
	}


	;_____________________________
	; 		CHECK INI FOR EXISTING
	;
	ini.partids
	
	
	
	last3 := StrRight(mandAssyNum, 3)
	assyNum := "9293-6" last3
	mandNum := "9290-2" last3

	;==================================================
	;							Search in CWI
	;==================================================
	IniRead, fieldXpos, %installDir%\Include\cwi sb\callibrationsettings.ini, fieldcoords, x
	IniRead, sText_y, %installDir%\Include\cwi sb\callibrationsettings.ini, fieldcoords, ST
	if !(fieldxpos || sText_y){
		msgbox, Calibrationsettings.INI file not found. Sorry, cant search in CWI.
		ExitApp
	}
	
	
	
	IfWinNotExist, Advanced Lookup -
	{
		run, http://cwiprod.corp.halliburton.com/cwi/AdvLookup.jsp
		winwait, Advanced Lookup -        
		StatusBarwait,Done,,1,Advanced Lookup -
		sleep 200
		StatusBarwait,Done,,1,Advanced Lookup -
		sleep, 200
		StatusBarwait,Done,,1,Advanced Lookup -
		sleep, 100
	}        
	BlockInput, on 
	settimer, unBlock, 2000
	sleep, 100        
	WinActivate, Advanced Lookup -
	IfWinNotActive, Advanced Lookup -
		WinActivate, Advanced Lookup -
	sleep, 100
	MouseClick,L,%fieldXpos%, %sText_y%, 3
	Sleep, 100
	SendInput, {blind}`"%mandAssyNum%`" OR `"%assyNum%`" OR `"%mandNum%`"
	sleep, 50
	SendInput, {blind}{tab}part{enter}
	BlockInput, off
	sleep 300

	currentRefNum = 9290-6XXX
	MsgBox, 0, , Hover your mouse over the 9290-6XXX part SAP NUM then press <F3>`n`nThen over the 9293-6XXX and press <F3>`n`nThen the 9290-2XXX.....`n`nCAREFUL!!   THEY ARENT ALWAYS IN THE SAME ORDER IN THE TABLE
return



;==== 9290-6xxx
#if !(mAssyID)
F6::
	MouseGetPos,,,id
	WinGetClass, wClass, ahk_id %id%
	if (wClass<>"IEFrame"){
		msgbox, Ooops... You need to be in a CWI window for this to work.... try again
		return
	}
	sbTxt:=StatusBarGetText("","Advanced Lookup Results -")
	StringReplace, partid, sbTxt, jsp?id=, $
	StringSplit,partID, partid, $
	mAssyID := partID2
return

;==== 9293-6xxx
#if (mAssyID && !assyID)
F7::
	currentRefNum = 9293-6XXX
	MouseGetPos,,,id
	WinGetClass, wClass, ahk_id %id%
	if (wClass<>"IEFrame"){
		msgbox, Ooops... You need to be in a CWI window for this to work.... try again
		return
	}
	sbTxt:=StatusBarGetText("","Advanced Lookup Results -")
	StringReplace, partid, sbTxt, jsp?id=, $
	StringSplit,partID, partid, $
	AssyID := partID2
return

;==== 9290-2xxx
#If (assyID && !mandID)
F8::
	currentRefNum = 9290-2XXX
	MouseGetPos,,,id
	WinGetClass, wClass, ahk_id %id%
	if (wClass<>"IEFrame"){
		msgbox, Ooops... You need to be in a CWI window for this to work.... try again
		return
	}
	sbTxt:=StatusBarGetText("","Advanced Lookup Results -")
	StringReplace, partid, sbTxt, jsp?id=, $
	StringSplit,partID, partid, $
	mandID := partID2
	If (assyID && mandID && massyID){	;==== Done - got all 3
		
		
		msgbox, Done!`n`n%mandAssyNum%=%massyID%`n%assyNum%=%assyID%`n%mandNum%=%mandid%
		
		cwi.Add_id(mandAssyNum, massyID)
		If ErrorLevel
			MsgBox something didnt work....
		else 
			MsgBox Done!
	}



unBlock:
	
return


#Include C:\dropbox\Code Repositories\PM App Launcher (SF-svn)\Include\CWI Functions\oCWI.ahk